import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kkhousekeep/page/login/login_controller.dart';
import 'package:kkhousekeep/page/me/me_page.dart';

import 'home_main_controller.dart';
import 'home_page.dart';

class HomeMainPage extends StatelessWidget {
  final int index;
  final UserType userType;

  const HomeMainPage({
    Key? key,
    this.index = 0,
    this.userType = UserType.tenant,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: HomeMainController(userType,index: index,),
      builder: (controller) => Scaffold(
        bottomNavigationBar: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(32.w),
                topRight: Radius.circular(32.w)),
            color: const Color(0x00f5f5f8),
          ),
          child: Obx(() => BottomNavigationBar(
                elevation: 0,
                currentIndex: controller.currentId.value,
                onTap: (index) => controller.switchBarItem(index),
                items: [
                  BottomNavigationBarItem(
                      icon: Image.asset(
                        'assets/images/home_bottom_navigation_home.png',
                        width: 60.w,
                        height: 60.w,
                      ),
                      label: "首页",
                      activeIcon: Image.asset(
                        'assets/images/home_bottom_navigation_home_active.png',
                        width: 60.w,
                        height: 60.w,
                      )),
                  BottomNavigationBarItem(
                      icon: Image.asset(
                        'assets/images/home_bottom_navigation_me.png',
                        width: 60.w,
                        height: 60.w,
                      ),
                      label: "我的",
                      activeIcon: Image.asset(
                        'assets/images/home_bottom_navigation_me_active.png',
                        width: 60.w,
                        height: 60.w,
                      )),
                ],
              )),
        ),
        body: Obx(() => Stack(
              children: [
                Visibility(
                  maintainState: true,
                  visible: controller.currentId.value == 0,
                  child: HomePage(
                    userType: userType,
                  ),
                ),
                Visibility(
                  maintainState: true,
                  visible: controller.currentId.value == 1,
                  child: const MePage(),
                ),
              ],
            )),
      ),
    );
  }
}
